package com.briup.jd2511.jd2511bookstore.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.springframework.core.annotation.Order;

/**
 * 定义切面类
 */
//@Aspect
//@Component
@Slf4j
@Order(1)
public class TimeAspect {

    // 编写环绕通知，在核心方法的前后添加时间记录
    @Around("com.briup.jd2511.jd2511bookstore.aspect.MyAspect1.pc()")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        // 记录开始时间
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        // 记录结束时间
        long end = System.currentTimeMillis();
        log.info("方法{}耗时{}毫秒", joinPoint.getSignature().getName(), (end - start));
        return result;
    }
}
